#ifndef STRATUM_CLIENT_H
#define STRATUM_CLIENT_H

#include "stratum.h"
#include "object.h"



#define STRATUM_JOB_MAX_HISTORY 16
#define MIN_ADDRESS_LEN 30
#define MAX_ADDRESS_LEN 35

class StratumSocket;
class StratumAlgo {
public:
    char   m_name[1024];
    double m_diff_multiplier; // 倍数
    double m_factor;          // 因子
    double m_profit;          // 利润
    double m_rent;            // 租金
    bool   m_overflow;

    STRATUM_HASH_FUNC m_hash_function;
    STRATUM_HASH_FUNC m_merkle_func;
};

class StratumClientAlgo {
public:
    double m_factor;
    StratumAlgo* m_algo;
};

class StratumClient : public StratumObject {
public:
    StratumSocket* m_sock;
    char m_notify_id[1024];
    int64_t m_req_id;
    int m_created;
    int m_last_best;

    bool m_reconnectable;
    bool m_reconnecting;

    int m_user_id;
    int m_worker_id;
    int m_coin_id;
    bool m_log_traffic;

    int m_id_int;
    const char* id_str;

    char m_version[1024];
    char m_username[1024];
    char m_password[1024];
    char m_worker[1024];

    double m_diff_actual;
    double m_diff_remote;
    double m_diff_written;
    bool m_diff_fixed;

    long long m_last_submit_time;
    double m_share_per_min;

    char m_extra_nonce1[32];
    char m_extra_nonce2size;

    char m_extra_nonce1_default[32];
    char m_extra_nonce2size_default;

    char m_extra_nonce1_last[32];
    char m_extra_nonce2size_last;

    char m_extra_nonce1_reconnect[32];
    char m_extra_nonce2size_reconnect;

    bool m_extra_nonce_subscribe;
    int m_submit_bad;

    double m_speed;
    int m_extra_nonce1_id;
    int m_job_id_next;
    int m_job_id_sent;
    int m_job_id_locked;

    StratumClientAlgo m_algos_subscribed[STRATUM_MAX_ALGOS];
    int m_job_history[STRATUM_JOB_MAX_HISTORY];
    int64_t m_shares;
    int m_stats;
    int m_donation;
    int m_broadcast_timeouts;
};



#endif //STRATUM_CLIENT_H
